<template>
  <!-- 轮播图组件 -->
  <el-carousel :interval="4000" type="card" height="300px">
    <el-carousel-item v-for="item in carouselList" :key="item.knowledgeId">
      <div class="carousel-item-image">
        <!-- 替换下面的路径为你的图片路径 -->
        <!-- <el-image
          :src="require(`@/assets/imgs/knowledge/${item}.jpg`)"
          alt="carousel-image"
        ></el-image> -->
        <el-image
          :src="item.cover"
          alt="carousel-image"
          fit="cover"
          style="heigth: 100%; width: 100%"
          @click="toTextDetail(item)"
        ></el-image>
      </div>
    </el-carousel-item>
  </el-carousel>
</template>

<script>
export default {
  name: "KnowledgeCarousel",
  created() {
    this.getKnowledgeList();
  },
  data() {
    return {
      count: 6,
      carouselList: [],
    };
  },
  methods: {
    getKnowledgeList() {
      this.$request.getHttp({
        url: "/knowledge/getKnowledgeList",
        params: {
          isCarousel: 1,
        },
        success: (data) => {
          console.log(data);
          if (data.code == 200) {
            this.carouselList = data.list;
          }
        },
        error: (error) => {},
      });
    },
    toTextDetail(item) {
      this.$router.push({
        name: "KnowledgeDetail", //必须使用路由名称
        params: { id: item.knowledgeid },
      });
    },
  },
};
</script>

<style scoped>
.carousel-item-image {
  width: 100%;
  height: 100%;
  overflow: hidden;
}

.carousel-item-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
</style>